package com.bearingnavi.android.overlays;

import android.view.MotionEvent;

import com.bearingnavi.android.views.LongpressMapView;
import com.bearingnavi.android.views.LongpressPopupPanel;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class CurrentPositionPointOverlay extends Overlay {
	private boolean isPinch = false;

	
	public CurrentPositionPointOverlay() {
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent e, MapView mapView) {
		
		int fingers = e.getPointerCount();
		if ( e.getAction() == MotionEvent.ACTION_DOWN ) isPinch=false;                  // touch down, don't know it's a pinch yet
		if ( e.getAction() == MotionEvent.ACTION_MOVE && fingers == 2 ) isPinch=true;     // Two fingers, def a pinch
		return super.onTouchEvent(e,mapView);
	}
	
	@Override
	public boolean onTap(GeoPoint p, MapView mapView) {
		
		if (isPinch || ((LongpressMapView)mapView).isLongpressHandled()) {
			return super.onTap(p, mapView);
		}
		
		if (LongpressPopupPanel.hide(mapView)) {
			return true;
		}
		
		return super.onTap(p, mapView);
	}
	
}
